/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package domain;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 *
 * @author ParaSait
 */
public class SettingsLoader {

    private static String FILENAME = "settings.cfg";

    private File file;
    private String email;
    private String rootDirectory;

    public SettingsLoader() {
        loadSettings();
    }

    private void loadSettings() {
        try {
            setEmail("");
            setRootDirectory("");
            
            file = new File(FILENAME);
            if (!file.exists()) {
                file.createNewFile();
            }
            
            BufferedReader reader = new BufferedReader(new FileReader(file));
            String line;
            int i = 0;
            while ((line = reader.readLine()) != null) {
                if(i == 0)
                    setEmail(line);
                else if(i == 1)
                    setRootDirectory(line);
                i++;
            }
            reader.close();
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }
    
    public void saveSettings()
    {
        try {
            file = new File(FILENAME);
            if (!file.exists()) {
                file.createNewFile();
            }
            
            PrintWriter writer = new PrintWriter(new FileWriter(file));
            writer.write(getEmail() + "\n");
            writer.write(getRootDirectory() + "\n");
            writer.close();
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }

    public String getEmail() {
        return email;
    }

    public String getRootDirectory() {
        return rootDirectory;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setRootDirectory(String rootDirectory) {
        this.rootDirectory = rootDirectory;
    }
}
